Developer Documentation

QuickTime 4 API Documentation

3D Graphics Programming with QuickDraw 3D 1.5.4

Previous | QD3D Book | Overview | Chapter Contents | Next |

Creating a View

A view is a collection of a model, a group of lights, a camera, a renderer, and a draw context. Now that you've defined functions that create all the requisite parts of a view (except the renderer), you can create a view, as illustrated in Listing 9 . To do this, you create a new empty view object and then explicitly add the parts to it.

To create an image in a window, a view must contain at least a camera, a renderer, and a draw context.

Listing 9 Creating a view

TQ3ViewObject MyNewView (WindowPtr theWindow)
{
    TQ3Status                           myStatus;
    TQ3ViewObject                       myView;
    TQ3DrawContextObject                myDrawContext;
    TQ3RendererObject                   myRenderer;
    TQ3CameraObject                     myCamera;
    TQ3GroupObject                      myLights;
    
    myView = Q3View_New();
    if (myView == NULL)
        goto bail;
    
    /*Create and set draw context.*/
    myDrawContext = MyNewDrawContext(theWindow);
    if (myDrawContext == NULL)
        goto bail;
    myStatus = Q3View_SetDrawContext(myView, myDrawContext);
    Q3Object_Dispose(myDrawContext);
    if (myStatus == kQ3Failure)
        goto bail;
    
    /*Create and set renderer.*/
    myRenderer = Q3Renderer_NewFromType(kQ3RendererTypeInteractive);
    if (myRenderer == NULL)
        goto bail;
    myStatus = Q3View_SetRenderer(myView, myRenderer);
    Q3Object_Dispose(myRenderer);
    if (myStatus == kQ3Failure)
        goto bail;

    /*Create and set camera.*/
    myCamera = MyNewCamera();
    if (myCamera == NULL)
        goto bail;
    myStatus = Q3View_SetCamera(myView, myCamera);
    Q3Object_Dispose(myCamera);
    if (myStatus == kQ3Failure)
        goto bail;

    /*Create and set lights.*/
    myLights = MyNewLights();
    if (myLights == NULL)
        goto bail;
    myStatus = Q3View_SetLightGroup(myView, myLights);
    Q3Object_Dispose(myLights);
    if (myStatus == kQ3Failure)
        goto bail;

    return (myView);
bail:
    /*If any of the above failed, then don't return a view.*/
    return (NULL);
}

© 1997 Apple Computer, Inc.

Previous | QD3D Book | Overview | Chapter Contents | Next |